package csel.view;

import java.awt.GridLayout;
import csel.model.Entity;
import csel.model.Observer;

import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.ImageIcon;


/*
 * Reasons for Existence: 
 * Team Members Responsible
 * Implementation: Alex, Andrew
 * Testing: Alex, Andrew
 */

public class AvatarViewer extends JPanel implements Observer
{

	public AvatarViewer(Entity e)
	{
		e.addObserver(this);
		
		setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));
        ImageIcon playerPic = new ImageIcon(RepresentationFactory.getInstance().get(e).getSimpleImage());
        JLabel avatarName = new JLabel(e.getName(),JLabel.CENTER);
        JLabel avatarPic = new JLabel(playerPic,JLabel.CENTER);
        JLabel avatarOcc = new JLabel(e.getOccupation().toString(),JLabel.CENTER);
        add(avatarPic);
        add(avatarName);
        add(avatarOcc);
	}
	
	public void setEntity(Entity e)
	{
		e.addObserver(this);
		modelUpdate(e);
	}
	
	public void modelUpdate(Object o)
	{
		Entity myEntity = (Entity) o;
		
		removeAll();
		ImageIcon playerPic = new ImageIcon(RepresentationFactory.getInstance().get(myEntity).getSimpleImage());
		JLabel avatarName = new JLabel(myEntity.getName(),JLabel.CENTER);
        JLabel avatarPic = new JLabel(playerPic,JLabel.CENTER);
        JLabel avatarOcc = new JLabel(myEntity.getOccupation().toString(),JLabel.CENTER);
        add(avatarPic);
        add(avatarName);
        add(avatarOcc);
        
        revalidate();
        //repaint();
	}
}